package wxshop.web.admin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wxshop.api.admin.exception.NameExist;
import wxshop.api.admin.exception.NameNotExist;
import wxshop.api.admin.exception.PasswordWrong;
import wxshop.api.admin.model.Admin;
import wxshop.api.admin.model.FormResult;
import wxshop.service.admin.impl.AdminServiceImpl;

/**
 * Created by 121874694@qq.com on 2018/03/01.
 */
@RestController
@RequestMapping("/admin")
public class LoginAndRegisterController {
    @Autowired
    private AdminServiceImpl adminService;
    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public FormResult register(@RequestBody Admin admin){
       return adminService.register(admin);
    }
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public FormResult login(@RequestBody Admin admin){
        return adminService.login(admin);
    }
    @ExceptionHandler
    public Object onException(NameExist e){
        System.out.println("进来了");
        return new FormResult(false,e.getMessage());
    }
    @ExceptionHandler
    public Object onException(NameNotExist e){
        return new FormResult(false,e.getMessage());
    }
    @ExceptionHandler
    public Object onException(PasswordWrong e){
        return new FormResult(false,e.getMessage());
    }
}
